#region Using directives
using System;
using System.Runtime.InteropServices;
#endregion

namespace SharpWind.Resources.Sound
{
	internal class FreeSL
	{
		#region Delegates

		public delegate void ErrorCalback( string error, bool isCritical );

		#endregion

		#region Structures

		[StructLayout( LayoutKind.Sequential )]
		public struct FSL_EAX_LISTENER_PROPERTIES
		{
			public long lRoom;						// room effect level at low frequencies
			public long lRoomHF;					// room effect high-frequency level re. low frequency level
			public float flRoomRolloffFactor;		// like DS3D flRolloffFactor but for room effect
			public float flDecayTime;				// reverberation decay time at low frequencies
			public float flDecayHFRatio;			// high-frequency to low-frequency decay time ratio
			public long lReflections;				// early reflections level relative to room effect
			public float flReflectionsDelay;		// initial reflection delay time
			public long lReverb;					// late reverberation level relative to room effect
			public float flReverbDelay;				// late reverberation delay time relative to initial reflection
			public ulong dwEnvironment;				// sets all listener properties
			public float flEnvironmentSize;			// environment size in meters
			public float flEnvironmentDiffusion;	// environment diffusion
			public float flAirAbsorptionHF;			// change in level per meter at 5 kHz
			public ulong dwFlags;					// modifies the behavior of properties
		};

		#endregion

		#region Methods

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSetErrorCallback@@YAXP6AXPBD_N@Z@Z" )]
		public static extern void fslSetErrorCallback( ErrorCalback callback );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslInit@@YA_NW4FSL_SOUND_SYSTEM@@@Z" )]
		public static extern bool fslInit( SoundSystem val );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslShutDown@@YAXXZ" )]
		public static extern void fslShutDown();

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSetVolume@@YAXM@Z" )]
		public static extern void fslSetVolume( float gain_mult );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslCountSoundsTotal@@YAHXZ" )]
		public static extern int fslCountSoundsTotal();

		[DllImport( "FreeSL.dll", EntryPoint = "?fslGetMaxSources@@YAHXZ" )]
		public static extern int fslGetMaxSources();

		[DllImport( "FreeSL.dll", EntryPoint = "?fslGetSoundMemoryUsage@@YAKXZ" )]
		public static extern uint fslGetSoundMemoryUsage();	

		[DllImport( "FreeSL.dll", EntryPoint = "?fslLoadSound@@YAIPBD@Z" )]
		public static extern uint fslLoadSound( string strFile );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslLoadSoundFromZip@@YAIPBD0@Z" )]
		public static extern uint fslLoadSoundFromZip( string strPackage, string strFile);

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundStop@@YAXI@Z" )]
		public static extern void fslSoundStop( uint obj );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundPlay@@YAXI@Z" )]
		public static extern void fslSoundPlay( uint obj );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundPause@@YAXI@Z" )]
		public static extern void fslSoundPause( uint obj );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundIsPlaying@@YA_NI@Z" )]
		public static extern bool fslSoundIsPlaying( uint obj );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundIsPaused@@YA_NI@Z" )]
		public static extern bool fslSoundIsPaused( uint obj );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundSetLooping@@YAXI_N@Z" )]
		public static extern void fslSoundSetLooping( uint obj, bool loop_sound );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundIsLooping@@YA_NI@Z" )]
		public static extern bool fslSoundIsLooping( uint obj );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslFreeSound@@YAXI_N@Z" )]
		public static extern void fslFreeSound( uint obj, bool remove_buffer );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundSetPosition@@YAXIMMM@Z" )]
		public static extern void fslSoundSetPosition( uint obj, float x, float y, float z);

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundSetVelocity@@YAXIMMM@Z" )]
		public static extern void fslSoundSetVelocity( uint obj, float x, float y, float z );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundSetPitch@@YAXIM@Z" )]
		public static extern void fslSoundSetPitch( uint obj, float pitch );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundSetGain@@YAXIM@Z" )]
		public static extern void fslSoundSetGain( uint obj, float gain );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundSetMaxDistance@@YAXIM@Z" )]
		public static extern void fslSoundSetMaxDistance( uint obj, float max_distance );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSoundSetReferenceDistance@@YAXIM@Z" )]
		public static extern void fslSoundSetReferenceDistance( uint obj, float ref_distance );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslLoadBuffer@@YAIPBD@Z" )]
		public static extern uint fslLoadBuffer( string strFile );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslDestroyBuffer@@YAXI@Z" )]
		public static extern void fslDestroyBuffer( uint obj);

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSetListenerPosition@@YAXMMM@Z" )]
		public static extern void fslSetListenerPosition( float x, float y, float z );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSetListenerVelocity@@YAXMMM@Z" )]
		public static extern void fslSetListenerVelocity(float x, float y, float z);

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSetListenerOrientation@@YAXMMMMMM@Z" )]
		public static extern void fslSetListenerOrientation( float atx, float aty, float atz, float upx, float upy, float upz);

		[DllImport( "FreeSL.dll", EntryPoint = "?fslLoadListenerEnvironment@@YA?AUFSL_EAX_LISTENER_PROPERTIES@@PBD@Z" )]
		public static extern FSL_EAX_LISTENER_PROPERTIES fslLoadListenerEnvironment( string strFile );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslLoadListenerEnvironmentFromZip@@YA?AUFSL_EAX_LISTENER_PROPERTIES@@PBD0@Z" )]
		public static extern FSL_EAX_LISTENER_PROPERTIES fslLoadListenerEnvironmentFromZip( string strPackage, string strFile);

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSetListenerEnvironment@@YAXPAUFSL_EAX_LISTENER_PROPERTIES@@@Z" )]
		public static extern void fslSetListenerEnvironment( FSL_EAX_LISTENER_PROPERTIES lpData );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSetListenerEnvironmentPreset@@YAXW4FSL_LISTENER_ENVIRONMENT@@@Z" )]
		public static extern void fslSetListenerEnvironmentPreset( Environment type );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSetMetersPerUnit@@YAXM@Z" )]
		public static extern void fslSetMetersPerUnit( float meters );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslInitSourceManager@@YAXH@Z" )]
		public static extern void fslInitSourceManager( int max_sources);

		[DllImport( "FreeSL.dll", EntryPoint = "?fslShutDownSourceManager@@YAXXZ" )]
		public static extern void fslShutDownSourceManager();

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSourceManagerGetSound@@YAII@Z" )]
		public static extern uint fslSourceManagerGetSound( uint b );

		[DllImport( "FreeSL.dll", EntryPoint = "?fslSourceManagerCountFreeSlots@@YAHXZ" )]
		public static extern int fslSourceManagerCountFreeSlots();

		#endregion
	}
}
